﻿using furion.blog.Domain.Shared;
using furion.blog.Domain.Shared.Enum;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace furion.blog.Domain.Query.TagConfig
{
    public class TagConfigListQuery : BaseQuery
    {
        public string SearchContent { get; set; } = string.Empty;
        public string Group { get; set; } = string.Empty;
        public string Status { get; set; } = string.Empty;
        public string IsDelete { get; set; } = YesOrNoEnum.No.ToString();

        /// <summary>
        /// 返回查询where 和 条件参数
        /// </summary>
        /// <returns></returns>
        public (string, List<SugarParameter>) QueryParams() {
            List<SugarParameter> parameters = new List<SugarParameter>();
            StringBuilder strWhere = new StringBuilder(" 1=1 ");
            if (!string.IsNullOrWhiteSpace(SearchContent)) {
                strWhere.AppendLine(" and (t.tagLabel like @searchContent " +
                    "or t.tagKey like @searchContent ) ");
                parameters.Add(new SugarParameter("searchContent","%"+ SearchContent + "%"));
            }
            if (!string.IsNullOrWhiteSpace(IsDelete)) {
                strWhere.AppendLine(" and t.isDelete=@isDelete ");
                parameters.Add(new SugarParameter("isDelete",IsDelete));
            }
            if (!string.IsNullOrWhiteSpace(Status))
            {
                strWhere.AppendLine(" and t.status=@status ");
                parameters.Add(new SugarParameter("status", Status));
            }
            if (!string.IsNullOrWhiteSpace(Group))
            {
                strWhere.AppendLine(" and t.groupKey=@groupKey ");
                parameters.Add(new SugarParameter("groupKey", Group));
            }
            return (strWhere.ToString(),parameters);
        }

    }
}
